package com.lgx.mobile.rest.topic;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lgx.mobile.entity.Topic;
import com.lgx.mobile.service.ITopicService;
import com.lgx.right.service.IUserService;

/**
 * 
 * @author xuyichen
 *
 */
@Controller
@RequestMapping("/getTopic")
public class GetTopicController {
	
	private static final Logger logger = Logger.getLogger(GetTopicController.class);

	@Autowired
	ITopicService topicService;
	
	public ITopicService getTopicService() {
		return topicService;
	}

	@Autowired
	IUserService userService;
	
	public IUserService getUserService() {
		return userService;
	}

	/**
	 * 话题查询
	 * @param topicId id is key
	 * @return 话题信息；0：话题不存在；1：参数异常，有参数为空
	 */
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	@ResponseBody
	public Object getTopic(@PathVariable("id") String topicId){
		if(StringUtils.isNotBlank(topicId)){
			Topic topic = getTopicService().findTopicById(Long.parseLong(topicId));
			if(topic != null){
				return topic;
			}else{
				if(logger.isDebugEnabled()){
					logger.debug("getTopic faild topicId is error");
				}
//				"getTopic faild please check topicId is exists";
				return "0";
			}
		}else{
			if(logger.isDebugEnabled()){
				logger.debug("getTopic faild topicId is not filled");
			}
//		    "getTopic faild please check topicId is filled";
			return "1";
		}
	}
}
